<?php
/**
 *
 * @author 李大牛家的牛 (scafel@163.com)
 * @className password.blade.php
 * @createDate 2025/7/31 - 9:21:56
 * @description
 **/
?>
@include('manage.default.template.header')
<div class="layui-container" style="width: 90%;padding-top: 10px;">
    <form class="layui-form" action="javascript:void(0);" method="post">
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-password"></i>
                </div>
                <input type="password" name="oldPassword" value="" lay-verify="required|checkRepeat" placeholder="原 始 密 码" lay-reqtext="请填写原始密码" autocomplete="off" class="layui-input" lay-affix="eye">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-password"></i>
                </div>
                <input type="password" name="newPassword" value="" lay-verify="required" id="newPassword" placeholder="新   密   码" lay-reqtext="请填写新密码" autocomplete="off" class="layui-input" lay-affix="eye">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-password"></i>
                </div>
                <input type="password" name="reNewPassword" value="" lay-verify="required|confirmPassword" placeholder="重复新密码" lay-reqtext="请填写重复新密码" autocomplete="off" class="layui-input" lay-affix="eye">
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="manage-admin-change-password">提交</button>
        </div>
    </form>
</div>
@include('manage.default.template.footer')
<script>
    layui.use(["util", "form", "interactive", "layer"], function () {
        var form = layui.form,
            layer = layui.layer,
            util = layui.util,
            $ = layui.jquery,
            req = layui.interactive;

        // 自定义验证规则
        form.verify({
            // 确认密码
            confirmPassword: function(value, item){
                var passwordValue = $('#newPassword').val();
                if(value !== passwordValue){
                    return '两次新密码输入不一致';
                }
            },
            checkRepeat: function(value, item){
                var passwordValue = $('#newPassword').val();
                if(value === passwordValue){
                    return '新密码不能与原始密码一致';
                }
            }
        });

        // 提交事件
        form.on('submit(manage-admin-change-password)', function (data) {
            const field = data.field; // 获取表单字段值
            req.post("/manage/admin/change/password", field, function (res) {
                top.location.reload();
            })
            return false; // 阻止默认 form 跳转
        });
    });
</script>
